// component/LuoAn/DeviceCell/DeviceCell.js


const animate = wx.createAnimation({
  delay: 10,
  duration:1000,
  timingFunction:'linear'
}).backgroundColor("#FF0000").step();

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    model:{
      type:Object,
      value:{},
      animate:{}
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    alarming:false// 是否正在报警
  },
  attached:function(e){
     
  },
  ready:function(e){

  },
  /**
   * 组件的方法列表
   */
  methods: {
    onClick:function(e){
      this.triggerEvent('onClick',this.data.model,{});
    },
    addressOnclick:function(e){
      this.triggerEvent('addressOnClick',this.data.model,{});
    },
  },
  observers:{
    'model':function(e){
      const model = e;
      const alarming = CheckAlarmFormat(model);
      if(alarming){ //如果报警；则闪烁
        if(this.timer){

        }else{
          this.timer = setInterval(e=>{
            this.setData({alarming:!this.data.alarming})
          },1000)
        }
      }else{
        this.timer&&clearInterval(this.timer)
      }
      this.setData({
        alarming:alarming
      })
    }
  }
})
const CheckAlarmFormat = function (item){
  if(item.manual=='Y'){ // 手动解除；不需要警告；返回false
    return false
  }else{
    if(item.smoketype=="Y"){
      return false
    }else{
      return true
    }
  }
}
